import React, { Component } from 'react'
// import { increment, decrement, incrementasync } from '../redux/action'
// import store  from '../redux/store'
export default class Count extends Component {
  add = () => {
    const { value } = this.selectVal
    this.props.add(value*1)
  }
  sub = () => {
    const { value } = this.selectVal
    this.props.sub(value*1)
  }
  incrementWherOdd = () => {
   const count = this.props.count
   if (count % 2 !== 0) {
     const { value } = this.selectVal
     this.props.add(value * 1)
   }
  }
  incrementAfter1s = () => {
      const { value } = this.selectVal
      this.props.addAsync(value * 1, 1000)
      // store.dispatch(incrementasync(value * 1, 1000))
  }
  componentDidMount(){
  //  store.subscribe(() => {
  //   //  this.forceUpdate()
  //   this.setState({})
  //  }) 
  }
  render () {
    console.log(this.props)
    // const { count } = this.state
    const { count } = this.props
    return (
      <div>
        <div className="header">计算之后的合为：{count }</div>
        <div className="opt">
          <select ref={val => this.selectVal = val}>
            <option value="1">1</option>
            <option value="2">2</option>
            <option value="3">3</option>
          </select>
          <button onClick={this.add}>+1</button>
          <button onClick={this.sub}>-1</button>
          <button onClick={this.incrementWherOdd}>count为奇数的时候加</button>
          <button onClick={this.incrementAfter1s}>1秒之后加</button>
        </div>
      </div>
    )
  }
}
